//
//  OELoginHomeViewController.m
//  OneEightyNine
//
//  Created by apple on 2019/3/1.
//  Copyright © 2019 stoneobs. All rights reserved.
//

#import "OERegisterFirstViewController.h"
#import "OERegisterSecViewController.h"
@interface OERegisterFirstViewController ()
@property(nonatomic, strong) UITextField                     *phoneTextFiled;/**<  */
@property(nonatomic, strong) STButton                     *nextButton;/**<  */
@end

@implementation OERegisterFirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configSubView];
    [self st_addAdjustView:self.nextButton offset:10];
    [self addNotifacations];
    // Do any additional setup after loading the view.
}
#pragma mark --Notifacation
- (void)addNotifacations{
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(st_notifactionMethod:)
                                                 name:UITextFieldTextDidChangeNotification
                                               object:nil];
    
}
- (void)st_notifactionMethod:(NSNotification*)notifacation{
    if (notifacation.object == self.phoneTextFiled) {
        if (self.phoneTextFiled.text.length == 11) {
            self.nextButton.backgroundColor =OE_LIMITE_COLOR;
            self.nextButton.userInteractionEnabled = YES;
        }else{
            self.nextButton.backgroundColor =UIColor.grayColor;
            self.nextButton.userInteractionEnabled = NO;
        }
    }

}
- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark --configSubView
- (void)configSubView{
    [self vhl_setNavBarBackgroundAlpha:0];
    
//    [self st_setLeftItemWithTitle:OESTRING(@"CANCEL") titleColor:FirstTextColor];
    
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 200)];
    
    
    UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"180×132LOGO"]];
    imageView.right = UIScreenWidth  -15;
    imageView.top = 20;
    [header addSubview:imageView];
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(15, imageView.centerY, imageView.left - 30, 100)
                                                     text:OESTRING(@"HI!\nWELCOME TO JOIN")
                                                textColor:FirstTextColor
                                                     font:18
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [header addSubview:titleLable];
    
    
    __weak typeof(self) weakSelf =  self;
    self.phoneTextFiled =  [self textFiledWithLeftTitle:[NSString stringWithFormat:@"%@ >",OE_PHONE_PREFIX]
                                           placeHolader:OESTRING(@"Phone number") rightView:nil];
    self.phoneTextFiled.top = titleLable.bottom + 40;
    [header addSubview:self.phoneTextFiled];
     self.phoneTextFiled.keyboardType = UIKeyboardTypeNumberPad;
    
    
    STButton * loginbutton = [[STButton alloc] initWithFrame:CGRectMake(15, self.phoneTextFiled.bottom, 200, 44)
                                                          title:OESTRING(@"Sign in")
                                                     titleColor:SecendTextColor
                                                      titleFont:14
                                                   cornerRadius:0
                                                backgroundColor:nil
                                                backgroundImage:nil
                                                          image:nil];
    [loginbutton setClicAction:^(UIButton *sender) {
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
    loginbutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    loginbutton.right = UIScreenWidth - 15;
    [header addSubview:loginbutton];
    
    
    
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(5, loginbutton.bottom + 20, UIScreenWidth - 30, 44)
                                                        title:OESTRING(@"NEXT")
                                                   titleColor:UIColor.whiteColor
                                                    titleFont:15
                                                 cornerRadius:22
                                              backgroundColor:UIColor.grayColor
                                              backgroundImage:nil
                                                        image:nil];
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    confimButton.centerX = self.tableView.width / 2;
    [header addSubview:confimButton];
    [confimButton setClicAction:^(UIButton *sender) {
//        if (![weakSelf.phoneTextFiled.text st_isValidatePhoneNumber]) {
//            [SVProgressHUD showInfoWithStatus:@""];
//            return ;
//        }
        OERegisterSecViewController * vc = OERegisterSecViewController.new;
        vc.phone = weakSelf.phoneTextFiled.text;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    
    self.nextButton = confimButton;
    self.nextButton.userInteractionEnabled = NO;
    STButton * emailButton = [self deflutButtonWithImage:@"70×70邮箱" handle:^{
        
    }];
    emailButton.centerX = UIScreenWidth / 2;
    emailButton.top = self.nextButton.bottom + 100;
    [header addSubview:emailButton];
    
    STButton * fButton = [self deflutButtonWithImage:@"70×70facebook" handle:^{
        
    }];
    fButton.right = emailButton.left - 40 ;
    fButton.top = self.nextButton.bottom + 100;
    [header addSubview:fButton];
    
    STButton * rButton = [self deflutButtonWithImage:@"70×70Instagram" handle:^{
        
    }];
    rButton.left = emailButton.right + 40 ;
    rButton.top = self.nextButton.bottom + 100;
    [header addSubview:rButton];
    
    header.height = rButton.bottom;
    self.tableView.tableHeaderView = header;
    self.tableView.backgroundColor = UIColor.whiteColor;
    self.tableView.showsVerticalScrollIndicator = NO;
}
- (STButton*)deflutButtonWithImage:(NSString*)imageName handle:(void(^)(void))handle{
    STButton * button = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)
                                                  title:nil
                                             titleColor:nil
                                              titleFont:0
                                           cornerRadius:0
                                        backgroundColor:nil
                                        backgroundImage:nil
                                                  image:[UIImage imageNamed:imageName]];
    [button setClicAction:^(UIButton *sender) {
        if (handle) {
            handle();
        }
    }];
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    return button;
    
}
- (UITextField*)textFiledWithLeftTitle:(NSString*)leftTitle placeHolader:(NSString*)placeHolader  rightView:(UIView*)rightView{
    UITextField * textFiled = [[UITextField alloc] initWithFrame:CGRectMake(15, 0, UIScreenWidth-30, 50)];
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, textFiled.height, textFiled.height)
                                                     title:leftTitle
                                                titleColor:OE_LIMITE_COLOR
                                                 titleFont:14
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:nil];
    buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    if (leftTitle.length) {
        textFiled.leftView = buyButton;
    }
    
    textFiled.leftViewMode = UITextFieldViewModeAlways;
    buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    textFiled.placeholder = placeHolader;
    
    textFiled.rightView = rightView;
    textFiled.rightViewMode = UITextFieldViewModeAlways;
    [textFiled st_showBottomLine];
    return textFiled;
}
@end
